
/* <<< COPYRIGHT START >>>
 * Copyright 2006-Present OxygenSoftwareLibrary.com
 * Licensed under the GNU Lesser General Public License.
 * http://www.gnu.org/licenses/lgpl.html
 * 
 * @author: Ugorji Dick-Nwoke
 * <<< COPYRIGHT END >>>
 */

package oxygen.tool.facade.plugins;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;

import oxygen.tool.facade.FacadePluginAdapter;
import oxygen.tool.facade.trees.JMXFacadeTreeModel;
import oxygen.tool.facade.trees.JMXUtils;
import oxygen.tool.facade.trees.TreeUtils;

public class GetMBeanAttribute extends FacadePluginAdapter {
  
  public Object execute(String key) throws Exception {
    JMXFacadeTreeModel ftm = (JMXFacadeTreeModel)TreeUtils.getCurrentTree(ctx);
    MBeanServerConnection mbs = ftm.getMBeanServerConnection();    
    ObjectName cmo = (ObjectName)ftm.getCurrentNode();
    cmo = JMXUtils.checkRegistered(mbs, cmo);
    
    return mbs.getAttribute(cmo, key);
  }
}

